package cn.kow.kmall.controller.admin;

import cn.kow.kmall.controller.BaseController;
import cn.kow.kmall.core.response.KmallResult;
import cn.kow.kmall.core.util.OSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author: lijun
 * @Description:
 * @Date: Created in 2019-05-13 15:27
 * @Modified By:
 */
@Slf4j
@RestController
@RequestMapping("/file")
public class FileController extends BaseController {

    @PostMapping("/upload")
    public KmallResult getOption(@RequestParam("file") MultipartFile file, @RequestParam(required = false, defaultValue = "tmp") String path) throws IOException {
        String fileName = file.getOriginalFilename();
        InputStream inputStream = file.getInputStream();
        String url = OSSUtils.uploadImage(path, inputStream, fileName);
        return KmallResult.success().put("url", url);
    }


}
